/*
*Copyright © 2019 XSNOW
*四川瑞韬科技有限公司
*http://www.ratotech.com.cn
*All rights reserved.
*/
package com.icesoft.xsnow.upms.controller;

import com.icesoft.xsnow.framework.api.reponses.R;
import com.icesoft.xsnow.framework.controller.BaseController;
import com.icesoft.xsnow.upms.api.po.SysRole;
import com.icesoft.xsnow.upms.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @program: xsnow
 * @description: 角色表 前端控制器
 * @author xuefeng.gao
 * @create: 2019-05-27
 */
@RestController
@Validated
@RequestMapping(value = "sys)/role", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(tags = {"SysRole"}, description = "角色表相关接口")
public class SysRoleController extends BaseController {
    @Autowired
    private  SysRoleService sysRoleService;

    @ApiOperation(" 通过id查询角色表")
    @ApiImplicitParams({ @ApiImplicitParam(name = " id", value = "id", required = true, paramType = "path") })
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return success(sysRoleService.getById(id));
    }

    @ApiOperation("分页查询角色表")
    @GetMapping("/page")
    public R page() {
        return success(sysRoleService.page(this.getPage()));
    }

    @ApiOperation("新增角色表")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('sys:role:add')" )
    public R save(@RequestBody SysRole sysRole) {
        return success(sysRoleService.save(sysRole));
    }

    @ApiOperation("修改角色表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('sys:role:edit')" )
    public R updateById(@RequestBody SysRole sysRole) {
        return success(sysRoleService.updateById(sysRole));
    }

    @ApiOperation("删除角色表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('sys:role:del')" )
    public R removeById(@PathVariable Integer id) {
        return success(sysRoleService.removeById(id));
    }

}
